﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Inventario_HardSoft.Controlador;
using Inventario_HardSoft.ADO;

namespace Inventario_HardSoft.Presentacion
{
    public partial class Historial_por_Tipo_Problema : Form
    { 
        private Count_TipoProb controlador;

        public Historial_por_Tipo_Problema()
        {
            InitializeComponent();
            controlador = new Count_TipoProb();
        }

        private void btn_Ver_Detalles_Click(object sender, EventArgs e)
        {
            //cuenta la cantidad de problemas por su tipo   
                double total;             
                txt_CountHw.Text = lblPsw.Text= txt_CountSw.Text = lblPhw.Text = String.Empty;         
                double contadProbHardware = Convert.ToDouble(controlador.contarProblemas("hardware"));
                double contadrobSoftware = Convert.ToDouble(controlador.contarProblemas("software"));
            //inserta cantidades
                txt_CountHw.Text = contadProbHardware.ToString();
                txt_CountSw.Text = contadrobSoftware.ToString();
                total = contadProbHardware + contadrobSoftware;
                txt_TotalProblemas.Text = total.ToString();
            //Calculo de porcentajes
                string a = ((contadProbHardware / total) * 100).ToString();
                string b = ((contadrobSoftware / total) * 100).ToString();
            //convierte a double
                double a1 = Double.Parse(a);
                double b1 = Double.Parse(b); 
            //muestra dos decimales
                lblPhw.Text = Math.Round(a1, 2).ToString();
                lblPsw.Text = Math.Round(b1, 2).ToString();      
            //convierto de texto a numero
                double h = Convert.ToDouble(a);
                double s = Convert.ToDouble(b);
            //pinta los paneles
                panel_Sw.BackColor = Color.Gold;
                panel_Hw.BackColor = Color.Blue;
            //modifico tamaños de los panels de estadisticas
                panel_Hw.Width = Convert.ToInt32(h);
                panel_Sw.Width = Convert.ToInt32(s);
        }


        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (rbHw.Checked)
            {
                //muestra problemas por hardware
                controlador.getLisProHw(grid_Hardware);
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (rbSw.Checked)
            {
                controlador.getLisProSw(grid_Hardware);
            }
        }

        private void Historial_por_Tipo_Problema_Load(object sender, EventArgs e)
        {
            comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
        }

        private void btnConsultar_Click(object sender, EventArgs e)
        {
            
                if (comboBox1.SelectedIndex == 0)
                {
                    if (rbHw.Checked)
                    {
                        controlador.fechaRegistroEntrada(grid_Hardware, Convert.ToDateTime(mskI1.Text).Date, Convert.ToDateTime(mskI2.Text).Date);
                    }
                    else if (rbSw.Checked)
                    {
                        controlador.fechaRegistroEntradaSoft(grid_Hardware, Convert.ToDateTime(mskI1.Text).Date, Convert.ToDateTime(mskI2.Text).Date);
                    }
                }
                else if (comboBox1.SelectedIndex == 1)
                {
                    if (rbHw.Checked)
                    {
                        controlador.fechaRegistroEntrega(grid_Hardware, Convert.ToDateTime(mskI1.Text).Date, Convert.ToDateTime(mskI2.Text).Date);
                    }
                    else if (rbSw.Checked)
                    {
                        controlador.fechaRegistroEntregaSfoft(grid_Hardware, Convert.ToDateTime(mskI1.Text).Date, Convert.ToDateTime(mskI2.Text).Date);
                    }
                }
                else if (comboBox1.SelectedIndex == 2)
                {
                    if (rbHw.Checked)
                    {
                        controlador.fechaRegistroSalida(grid_Hardware, Convert.ToDateTime(mskI1.Text).Date, Convert.ToDateTime(mskI2.Text).Date);
                    }
                    else if (rbSw.Checked)
                    {
                        controlador.fechaRegistroSalidaSoft(grid_Hardware, Convert.ToDateTime(mskI1.Text).Date, Convert.ToDateTime(mskI2.Text).Date);
                    }
                } 
       }
         
        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void btnNuevo_Click(object sender, EventArgs e)
        {
            rbHw.Checked=false;
            rbSw.Checked=false;
 
            mskI1.Text="";
            mskI2.Text="";
 
            grid_Hardware.Rows.Clear();
            
            txt_CountHw.Text = "";
            txt_CountSw.Text = "";
            txt_TotalProblemas.Text = "";
            lblPhw.Text = "";
            lblPsw.Text = "";
            panel_Hw.Width = Convert.ToInt32(0);
            panel_Sw.Width = Convert.ToInt32(0);
        }
         

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        { 
          
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked)
            {
                mskI1.Enabled = true;
                mskI2.Enabled = true;
                grid_Hardware.Rows.Clear();      
                comboBox1.Enabled = true;
                btnConsultar.Visible = true;
                mskI2.Text = DateTime.Now.ToString("dd/MM/yyyy"); 
        
            }
            else
            {
                mskI1.Enabled = false;
                mskI2.Enabled = false;
                mskI1.Text = "";
                mskI2.Text = "";
                btnConsultar.Visible = false;
                comboBox1.Enabled = false;
                comboBox1.SelectedIndex = -1;
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (grid_Hardware.Height == 574)
            {
                grid_Hardware.Width = 1158;
                grid_Hardware.Height = 424;
                groupBox1.Location = new Point(12, 530);
                groupBox1.Width = 1150;
                groupBox1.Height = 152;
            }
            else
            {
                grid_Hardware.Width = 1158;
                grid_Hardware.Height = 574;
                groupBox1.Location = new Point(12, 665);
                groupBox1.Width = 1150;
                groupBox1.Height = 19;        
            }





        }

 
   }
}
